<template>
  <div>
    <h2>
      控制一次并发个数 查看控制台 express-system 执行 'node ./bin/demo.js'
    </h2>
    {{ res }}
  </div>
</template>

<script>
// import "@/utils/queue-task"
function f(myRequest) {
  return () => {
    return new Promise((r, j) => {
      fetch(myRequest)
        .then((response) => {
          if (response.status === 200) {
            return response.json();
          } else {
            throw new Error("Something went wrong on api server!");
          }
        })
        .then((response) => {
          r(response);
        })
        .catch((error) => {
          console.error(error);
        });
    });
  };
}
import jsAsyncPool from "js-asyncpool";
function createPromise(j) {
  return () => {
    return new Promise((resolve) => {
      // console.log(`promise${j} start`);
      setTimeout(() => {
        console.log(`promise${j} over------`);
        resolve(j);
      }, 1000);
    });
  };
}
export default {
  data() {
    return {
      arr: [],
      res: "",
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      for (let i = 0; i < 73; i++) {
        this.arr.push(f("http://localhost:7001"));
        // this.arr.push(createPromise(i));
      }
      // console.log(this.arr, '----arr')
      jsAsyncPool.asyncPool(this.arr, 6).then((res) => {
        this.res = res;
      });
    },
  },
};
</script>

<style lang="less" scoped></style>
